package service

import (
	"ginProject/biz/model"
	"ginProject/biz/utils"
)

/**
 * @Author leibidong
 * @Description 登录处理验证service层
 * @Date  2021/7/11 17:37
 **/
func UserLogin(loginName string, password string) (id int) {
	customerLogin := model.Login(loginName)
	if customerLogin != (model.CustomerLogin{}) {
		if customerLogin.Password == utils.GetMD5(password) {
			if customerLogin.Status == 0 {
				model.UpdateStatus(customerLogin.ID)
				return customerLogin.ID
			} else {
				return customerLogin.ID
			}
		} else {
			return 0
		}
	} else {
		t := utils.GetTime()
		var customerLogin = model.CustomerLogin{IsAdmin: 1, Password: utils.GetMD5(password),
			LoginName: loginName, CreateTime: t, ModifiedTime: t, Status: 1}
		model.InsertLogin(customerLogin)
		customerLogin1 := model.Login(loginName)
		return customerLogin1.ID
	}
}

/**
 * @Author leibidong
 * @Description 退出登录service层
 * @Date  2021/7/11 17:38
 **/
func UserLogout(id int) (status int) {
	s := model.QueryStatusById(id)
	if s == 1 {
		model.UpdateStatusToZero(id)
		return 1
	} else {
		return 0
	}

}
